#!/bin/bash

# Copyright 2021 NXP
#
# SPDX-License-Identifier: BSD-3-Clause


clean_bsp_components() {
    rm -rf $FBOUTDIR/bsp
    rm -rf $PKGDIR/bsp/atf/build

    [ -d $PKGDIR/bsp/rcw ] && \
    $MAKE clean -C $PKGDIR/bsp/rcw 2>/dev/null

    [ -d $PKGDIR/bsp/mc_utils/config ] &&
    $MAKE clean -C $PKGDIR/bsp/mc_utils/config
}


clean_linux_components() {
    rm -rf $FBOUTDIR/linux
}


clean_apps_components() {
    # staging build directory
    rm -rf $DESTDIR

    [ -d $PKGDIR/apps/networking/vpp/build-root ] && \
    $MAKE distclean -C $PKGDIR/apps/networking/vpp/build-root

    [ -d $PKGDIR/apps/networking/fmc/source ] && \
    $MAKE clean -C $PKGDIR/apps/networking/fmc/source

    [ -d $PKGDIR/apps/security/optee_os ] && \
    $MAKE clean -C $PKGDIR/apps/security/optee_os ARCH=arm

    [ -d $PKGDIR/apps/security/optee_client ] && \
    rm -rf $PKGDIR/apps/security/optee_client/out

    [ -d $PKGDIR/apps/security/keyctl_caam ] && \
    $MAKE clean -C $PKGDIR/apps/security/keyctl_caam

    [ -d $PKGDIR/apps/security/libpkcs11 ] && \
    $MAKE clean -C $PKGDIR/apps/security/libpkcs11

    rm -rf $PKGDIR/apps/security/optee_test/out

    find $PKGDIR/apps -name build_${DISTROTYPE}_$ARCH | xargs rm -rf
    rm -f $FBOUTDIR/apps/.app${DESTARCH}${DISTROTYPE}${DISTROVARIANT}${SOCFAMILY}
}
